const request = require('./request.js').default;

/**
 * 书籍相关 API
 */
const bookAPI = {
  /**
   * 获取每日一句
   * @param {number} userId - 用户ID
   */
  getDailyQuote: (userId) => request('/daily-quote/getDailyQuote', 'POST', { id: userId }),

  /**
   * 提交每日一句答案
   * @param {Object} data - 答题数据
   * @param {number} data.id - 题目ID
   * @param {number} data.userId - 用户ID
   * @param {string} data.answer - 用户答案
   */
  submitDailyQuoteAnswer: (data) => request('/daily-quote/submitAnswer', 'POST', data),

  /**
   * 搜索书籍
   * @param {Object} params - 搜索参数
   * @param {string} params.keyword - 搜索关键词
   * @param {number} params.page - 页码
   * @param {number} params.pageSize - 每页数量
   */
  searchBooks: (params = {}) => request('/books/search', 'GET', params),

  /**
   * 根据书名模糊搜索书籍
   * @param {string} title - 书名关键词
   */
  searchBooksByName: (title) => request('/book/searchBooksByName', 'POST', { title }),

  /**
   * 根据书名查询书籍信息
   * @param {string} title - 书名
   */
  getBookInfoByName: (title) => request('/book/getBookInfoByName', 'POST', { title }),

  /**
   * 保存书籍信息
   * @param {Object} bookData - 书籍信息
   */
  saveBookInfo: (bookData) => request('/book/saveBookInfo', 'POST', bookData),

  /**
   * 保存书摘信息
   * @param {Object} quoteData - 书摘信息
   */
  saveQuoteInfo: (quoteData) => request('/book/saveQuoteInfo', 'POST', quoteData),

  /**
   * 获取书籍详情
   * @param {string} bookId - 书籍ID
   */
  getBookDetail: (bookId) => request(`/books/${bookId}`, 'GET'),

  /**
   * 根据书籍ID获取书籍信息
   * @param {number} bookId - 书籍ID
   */
  getBookById: (bookId) => request('/book/getBookById', 'POST', { bookId }),

  /**
   * 获取推荐书籍列表
   * @param {Object} params - 查询参数
   */
  getRecommendedBooks: (params = {}) => request('/books/recommended', 'GET', params),

  /**
   * 获取我的书单
   * @param {Object} params - 查询参数
   */
  getMyBooks: (params = {}) => request('/books/my', 'GET', params),

  /**
   * 添加书籍到书单
   * @param {string} bookId - 书籍ID
   */
  addToMyBooks: (bookId) => request('/books/my', 'POST', { bookId }),

  /**
   * 从书单移除书籍
   * @param {string} bookId - 书籍ID
   */
  removeFromMyBooks: (bookId) => request(`/books/my/${bookId}`, 'DELETE'),

  /**
   * 获取书籍分类
   */
  getBookCategories: () => request('/books/categories', 'GET'),

  /**
   * 根据分类获取书籍
   * @param {string} categoryId - 分类ID
   * @param {Object} params - 查询参数
   */
  getBooksByCategory: (categoryId, params = {}) => request(`/books/category/${categoryId}`, 'GET', params),

  /**
   * 获取热门书籍
   * @param {Object} params - 查询参数
   */
  getPopularBooks: (params = {}) => request('/books/popular', 'GET', params),

  /**
   * 获取新书推荐
   * @param {Object} params - 查询参数
   */
  getNewBooks: (params = {}) => request('/books/new', 'GET', params),

  /**
   * 获取用户阅读历史
   * @param {Object} params - 查询参数
   */
  getUserReadingHistory: (params = {}) => request('/books/reading-history', 'GET', params),

  /**
   * 标记书籍为已读
   * @param {string} bookId - 书籍ID
   */
  markBookAsRead: (bookId) => request(`/books/${bookId}/read`, 'POST'),

  /**
   * 获取书籍评分
   * @param {string} bookId - 书籍ID
   */
  getBookRating: (bookId) => request(`/books/${bookId}/rating`, 'GET'),

  /**
   * 为书籍评分
   * @param {string} bookId - 书籍ID
   * @param {Object} data - 评分数据
   * @param {number} data.rating - 评分（1-5）
   * @param {string} data.comment - 评价内容
   */
  rateBook: (bookId, data) => request(`/books/${bookId}/rating`, 'POST', data)
};

module.exports = { bookAPI };
